﻿// Write a program that exchanges bits 3, 4 and 5 with bits 24, 25 and 26 of given 32-bit unsigned integer.

using System;

class Exchange6Bits
{
    static void Main()
    {
        Console.Write("Enter number: ");
        uint number = uint.Parse(Console.ReadLine());

        if (number < 8)
        {
            Console.WriteLine("Your number has 0 in its 3rd, 4th, 5th, 24th, 25th and 26th bits, so its exchanged number is the same as it.");
        }

        uint mask = 1;

        uint mask3Position = mask << 3;
        uint numberAndMask3 = number & mask3Position;
        uint value3Bit = numberAndMask3 >> 3;

        uint mask4Position = mask << 4;
        uint numberAndMask4 = number & mask4Position;
        uint value4Bit = numberAndMask4 >> 4;

        uint mask5Position = mask << 5;
        uint numberAndMask5 = number & mask5Position;
        uint value5Bit = numberAndMask5 >> 5;

        uint mask24Position = mask << 24;
        uint numberAndMask24 = number & mask24Position;
        uint value24Bit = numberAndMask24 >> 24;

        uint mask25Position = mask << 25;
        uint numberAndMask25 = number & mask25Position;
        uint value25Bit = numberAndMask25 >> 25;

        uint mask26Position = mask << 26;
        uint numberAndMask26 = number & mask26Position;
        uint value26Bit = numberAndMask26 >> 26;

        uint numberExchanged = 0;

        // put 3rd bit to 24th position
        uint mask24;
        if (value3Bit == 1)
        {
            mask24 = mask << 24;
            numberExchanged = number | mask24;
        }
        else if (value3Bit == 0)
        {
            mask24 = ~(mask << 24);
            numberExchanged = number & mask24;
        }

        // put 4th bit to 25th position
        uint mask25;
        if (value4Bit == 1)
        {
            mask25 = mask << 25;
            numberExchanged = numberExchanged | mask25;
        }
        else if (value4Bit == 0)
        {
            mask25 = ~(mask << 25);
            numberExchanged = numberExchanged & mask25;
        }

        // put 5th bit to 26th position
        uint mask26;
        if (value5Bit == 1)
        {
            mask26 = mask << 26;
            numberExchanged = numberExchanged | mask26;
        }
        else if (value5Bit == 0)
        {
            mask26 = ~(mask << 26);
            numberExchanged = numberExchanged & mask26;
        }

        // put 24th bit to 3rd position
        uint mask3;
        if (value24Bit == 1)
        {
            mask3 = mask << 3;
            numberExchanged = numberExchanged | mask3;
        }
        else if (value24Bit == 0)
        {
            mask3 = ~(mask << 3);
            numberExchanged = numberExchanged & mask3;
        }

        // put 25th bit to 4th position
        uint mask4;
        if (value25Bit == 1)
        {
            mask4 = mask << 4;
            numberExchanged = numberExchanged | mask4;
        }
        else if (value25Bit == 0)
        {
            mask4 = ~(mask << 4);
            numberExchanged = numberExchanged & mask4;
        }

        // put 26th bit to 5th position
        uint mask5;
        if (value26Bit == 1)
        {
            mask5 = mask << 5;
            numberExchanged = numberExchanged | mask5;
        }
        else if (value26Bit == 0)
        {
            mask5 = ~(mask << 5);
            numberExchanged = numberExchanged & mask5;
        }

        Console.WriteLine("The new number after exchanging of bits is: " + numberExchanged);

    }
}
